package cn.edu.njust.control;


import cn.edu.njust.pojo.User;
import cn.edu.njust.service.impl.trServiceImpl;
import cn.edu.njust.service.trService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "showServlet", value = "/showServlet")
public class ShowServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session1 = request.getSession();

        User loginUser = (User) session1.getAttribute("loginUser");

        trService tr = new trServiceImpl();

        List<Integer> trs = tr.selectAllGrade(loginUser.getIdNo());

        String jsonString = JSON.toJSONString(trs);

        System.out.println(jsonString);

        response.setContentType("text/json;charset=UTF-8");
        response.getWriter().write(jsonString);

//        for (int i = 0; i < trs.size(); i++) {
//            int tr1 = trs.get(i);
//        }

    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

}
